package fi.foyt.cs.controller;

import java.util.List;

import fi.foyt.cs.persistence.dao.items.ItemDAO;
import fi.foyt.cs.persistence.dao.items.StashedItemDAO;
import fi.foyt.cs.persistence.domainmodel.items.Item;
import fi.foyt.cs.persistence.domainmodel.items.StashedItem;
import fi.foyt.cs.persistence.domainmodel.locale.LocaleElement;
import fi.foyt.cs.persistence.domainmodel.scene.Scene;
import fi.foyt.cs.persistence.domainmodel.user.User;

public class ItemController {
  
  public Item createItem(LocaleElement localeElement, String icon) {
    ItemDAO itemDAO = new ItemDAO();
    return itemDAO.create(localeElement.getId().getId(), icon);
  }

  public Item findItemById(Long id) {
    ItemDAO itemDAO = new ItemDAO();
    return itemDAO.findById(id);
  }
  
  public List<Item> listAllItems() {
    ItemDAO itemDAO = new ItemDAO();
    return itemDAO.listAll();
  }
  
  public Item updateIcon(Item item, String icon) {
    ItemDAO itemDAO = new ItemDAO();
    return itemDAO.updateIcon(item, icon);
  }
  
  public void deleteItem(Item item) {
    ItemDAO itemDAO = new ItemDAO();
    itemDAO.delete(item);
  }
  
  public StashedItem createStashedItem(User user, Item item, Scene scene, Integer count) {
    StashedItemDAO stashedItemDAO = new StashedItemDAO();
    return stashedItemDAO.create(user.getId().getId(), scene.getId().getId(), item.getId().getId(), count);
  }
  
  public StashedItem findStashedItemByUserAndSceneAndItem(User user, Item item, Scene scene) {
    StashedItemDAO stashedItemDAO = new StashedItemDAO();
    return stashedItemDAO.findByUserIdAndItemIdAndSceneId(user.getId().getId(), item.getId().getId(), scene.getId().getId());
  }
  
  public List<StashedItem> listStashedItemsByUser(User user) {
    StashedItemDAO stashedItemDAO = new StashedItemDAO();
    return stashedItemDAO.listByUserId(user.getId().getId());
  }
  
  public List<StashedItem> listStashedItemsByUserAndScene(User user, Scene scene) {
    StashedItemDAO stashedItemDAO = new StashedItemDAO();
    return stashedItemDAO.listByUserIdAndSceneId(user.getId().getId(), scene.getId().getId());
  }
  
  public StashedItem updateStashedItemCount(StashedItem stashedItem, Integer count) {
    StashedItemDAO stashedItemDAO = new StashedItemDAO();
    return stashedItemDAO.updateCount(stashedItem, count);
  }

  public void deleteStashedItem(StashedItem stashedItem) {
    StashedItemDAO stashedItemDAO = new StashedItemDAO();
    stashedItemDAO.delete(stashedItem);
  }
}
